import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
// import Msite from '../pages/Msite/Msite.vue'
// import Order from '../pages/Order/Order.vue'
// import Profile from '../pages/Profile/Profile.vue'
// import Search from '../pages/Search/Search.vue'
// import Login from '../pages/Login/Login.vue'
// import Shop from '../pages/Shop/Shop.vue'
// import ShopGoods from '../pages/Shop/ShopGoods/ShopGoods.vue'
// import ShopInfo from '../pages/Shop/ShopInfo/ShopInfo.vue'
// import ShopRatings from '../pages/Shop/ShopRatings/ShopRatings.vue'
//component: ()=>import('../pages/Msite/Msite.vue'),  路由懒加载
const router = new VueRouter({
    routes: [
        { path: '/', redirect: '/msite' },  //重定向
        {
            path: '/msite',
            component: ()=>import('../pages/Msite/Msite.vue'),
            meta: {
                showFooter: true
            }
        },
        {
            path: '/order', component: ()=>import('../pages/Order/Order.vue'),
            meta: {
                showFooter: true
            }
        },
        {
            path: '/profile', component: ()=>import('../pages/Profile/Profile.vue'),
            meta: {
                showFooter: true
            }
        },
        {
            path: '/search', component: ()=>import('../pages/Search/Search.vue'),
            meta: {
                showFooter: true
            }
        },

      {
        path: '/shop', component: ()=>import('../pages/Shop/Shop.vue'),
        // meta: {
        //     showFooter: true
        // },
        children:[
          {path: '/shop/goods', component: ()=>import('../pages/Shop/ShopGoods/ShopGoods.vue')},
          {path: '/shop/info', component: ()=>import('../pages/Shop/ShopInfo/ShopInfo.vue')},
          {path: '/shop/ratings', component: ()=>import('../pages/Shop/ShopRatings/ShopRatings.vue')},
          {path:'',redirect:'/shop/goods'}
        ],

    },
        { path: '/login', component: ()=>import('../pages/Login/Login.vue')}    //meta:{} 默认就有 默认就是空对象
    ]

})

//路由守卫

router.beforeEach((to, from, next) => {
  //获取 缓存中的用户ID
let userInfoId=window.localStorage.getItem('userInfoId');
  if(to.path=='/login'){
    next()
  }else{
    if(userInfoId){
      next()
    }else{
      next('/login')
    }
  }
})
export default router
